﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UMLTouch.Core.Entities;

namespace UMLTouch.DomainRecognition.ShapeRecognition
{



    public struct ShapeMatchingResult
    {
        private ShapePatternMatchingResultEnum _matching;

        public ShapePatternMatchingResultEnum Matching
        {
            get { return _matching; }
            set { _matching = value; }
        }
        private IShapePattern _matchingPattern;

        public IShapePattern MatchingPattern
        {
            get { return _matchingPattern; }
            set { _matchingPattern = value; }
        }

        public ShapeMatchingResult(ShapePatternMatchingResultEnum matching, IShapePattern matchingPattern)
        {
            _matching = matching;
            _matchingPattern = matchingPattern;
        }
    }




    public class ShapeRecognizer
    {
        public List<IShapePattern> ShapePatterns { get; set; }



        public ShapeRecognizer()
        {
            ShapePatterns = new List<IShapePattern>();
        }

        public ShapeRecognizer(List<IShapePattern> patterns)
        {
            ShapePatterns = patterns;
        }


        public virtual IEnumerable<ShapeMatchingResult> Match(Shape shape)
        {
            var ret = (from sp in ShapePatterns
                       let matchingResult = sp.Match(shape)
                       where matchingResult != ShapePatternMatchingResultEnum.DontMatch
                       select new ShapeMatchingResult(matchingResult, sp)).ToList();

            return ret;
        }


    }
}
